﻿document.observe("dom:loaded", loadMainDealComments);

//chú ý khi upload file.
//các function sử dụng biến strUrlLink: showCommentsByDeal(); showSubCommentSPResult(); 
//var strUrlLink = "http://pcw028/NhomMua_new/"; 

function loadMainDealComments() {

    //check trạng thái đăng nhập
    try { checkSession(); } catch (e) { }
    //check comment nhập trong trạng thái chưa login.
    try { checkComment(); } catch (e) { }
    //check sub-comment nhập trong trạng thái chưa login.
    try { checkSubComment(); } catch (e) { }

    //nút Gửi comment cho san pham
    if ($("btnSend")) {
        $("btnSend").onclick = sendCommentDeal;
    }

    try {
        showLisrReferrer();
    } catch (ex) { if ($("divReferrer")) $("divReferrer").style.display = "none"; }

    if ($("dListSP_GioiThieu")) {
        eventGioThieuSanPham();
    }

    if ($("dMap")) {
        loadMap();
    }
    // 16.4.12
    if (document.getElementById("ddlEmailDetail")) {
        var ddlDetail = new ddlDD_Detail();
        ddlDetail.initializeCtrl('ddlEmailDetail', onLoadDDL_Detail, onChangeCitiesDetail, true); //edit here 28/02 2:12PM
    }
    if ($('btnSendMailSameDeal')) {
        $('btnSendMailSameDeal').onclick = SendEmailNhanGiaTotDetail;
    }
    // end 16.4.12
    // 2.5.12
    if ($("dRedeal")) {
        setPopUpCenter("dRedeal");
        window.onresize = function() {
            setPopUpCenter("dRedeal");
        };
    }
    //End 2.5.12
	//23.10.2012
    if ($('aBtnViewInEnglish')) {
        $('aBtnViewInEnglish').onclick = changeDetail_Lang;
    }
//09/01/2013
    if ($('dPagingMDT')) {
        $('dPagingMDT').select('a').invoke('observe', 'click', changePageMDT);
    }
    //14/01/2013
    if ($('dPopupRewardDeal') && trim($('dPopupRewardDeal').innerHTML) != "") {
        setPopUpCenter('dPopupRewardDeal');
        $('dShadow').show();
        $('dPopupRewardDeal').show();
        $('iClosePopup').onclick = function() {
            $('dPopupRewardDeal').hide();
            $('dShadow').hide();
        };
    }
    if ($('dPagingMDT_Popup')) {
        $('dPagingMDT_Popup').select('a').invoke('observe', 'click', changePageMDT_Popup);
    }
}
//xử lý kiểm tra comment
function checkComment() {
    if (GetCookie("txtCommentDeal") != null && GetCookie("txtCommentDeal") != "") {
        $("txtCommentDeal").value = GetCookie("txtCommentDeal");
    };
}
//xử lý insert comment
function sendCommentDeal() {
    var strUrlLocation = window.location.href;
    strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        strUrlLink = strPathLink_All + "yahoo/";
    }
    if (objLogin != null) {
        if ($("txtCommentDeal").value.length > 0) {
            $("btnSend").onclick = "";
            if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
                utils.call(strUrlLink + "nhommua/deal_comments.aspx", { "flag": "insert", "desc": $("txtCommentDeal").value, "id": strDealID }, "POST", "sendCommentDealResult", "sendCommentDealResult");
            }
            else {
                utils.call(strUrlLink + strStateNM + "/nhommua/deal_comments.aspx", { "flag": "insert", "desc": $("txtCommentDeal").value, "id": strDealID }, "POST", "sendCommentDealResult", "sendCommentDealResult");
            }
        }
    } else {
        if ($("txtCommentDeal").value.length > 0)
            SetCookie("txtCommentDeal", $("txtCommentDeal").value, 60);

        //N1.18.11
        window.open(strUrlLink + strStateNM + "/login.aspx" + (strLangNM == "en" ? "?lang=en" : ""), "_self");
        //N1.18.11 end
    }
}
//xử lý kết quả trả về sau khi insert comment
function sendCommentDealResult(strResult) {
    if (strResult != "0") {
        DeleteCookie("txtCommentDeal", "");
        $("txtCommentDeal").value = "";
        $("btnSend").onclick = sendCommentDeal;
        var strUrlLocation = window.location.href;
        strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            strUrlLink = strPathLink_All + "yahoo/";
        }
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            utils.call(strUrlLink + "nhommua/deal_comments.aspx", { "flag": "view", "id": strDealID }, "POST", "showCommentsByDeal", "showCommentsByDeal");
        } else {
            utils.call(strUrlLink + strStateNM + "/nhommua/deal_comments.aspx", { "flag": "view", "id": strDealID }, "POST", "showCommentsByDeal", "showCommentsByDeal");
        }

    } else
        $("btnSend").onclick = sendCommentDeal;
}
//xử lý hiển thị comment của sản phẩm
function showCommentsByDeal(objComment) {

    var strHtml = "";
    for (var i = 0; i < objComment.dsComment.length; i++) {

        strHtml += "<div class='comment-content'>";
        strHtml += "<div class='detail-deal'>";
        strHtml += "<p>" + objComment.dsComment[i].noidung + "</p>";
        //28.12.1
        var flag = 0;
        if (objComment.dsComment[i].idtk == "138503" || objComment.dsComment[i].idtk == "306400" || objComment.dsComment[i].idtk == "101450" || objComment.dsComment[i].idtk == "961214" || objComment.dsComment[i].idtk == "997623") {
            flag = 1;
        }
        else if (objComment.dsComment[i].merchantid != "" && parseInt(objComment.dsComment[i].merchantid) > 0) {
            flag = 2;
        }
        else if (objComment.dsComment[i].nmrankcate != "0") {
            flag = 3;
        }
        var clas = "user-info ";
        var strNameUser = "";
        strNameUser = " - <em>" + objComment.dsComment[i].rankname + "</em>";
        switch (objComment.dsComment[i].rankid) {
            case "1":
                clas += "vip-dif";
                break;
            case "2":
                clas += "vip-clo";
                break;
            case "3":
                clas += "vip-sim";
                break;
            case "4":
                clas += "vip-sil";
                break;
            case "5":
                clas += "vip-gol";
                break;
            case "6":
                clas += "vip-dia";
                break;
            default:
                clas += "vip-dif";
        }
        if (flag == 1 || flag == 2) {
            strHtml += "<p class='" + clas + "' style='background:none;padding-left:0'>";
            strNameUser = "";
        }
        else {
            strHtml += "<p class='" + clas + "'>";
        }
        strHtml += "<a href='profile/comments.aspx?mid=" + objComment.dsComment[i].idtk + (strLangNM == "en" ? "&lang=en" : "") + "' name=''>" + objComment.dsComment[i].nickname + "</a>" + strNameUser + "<span>" + objComment.dsComment[i].tgtao + "</span></p>";
        strHtml += "<div class='total-comment' style='cursor: pointer;' onclick='showSubCommentSP(" + objComment.dsComment[i].idcomment + ")' >";
        strHtml += "<span class='icon-comment'></span>";
        strHtml += "<span class='num-comment' id='subCount_" + objComment.dsComment[i].idcomment + "'>" + objComment.dsComment[i].counts + " " + (strLangNM == "en" ? "comments" : "lời bình") + "</span>";

        strHtml += "</div>";
        strHtml += "</div>";
        strHtml += "<i></i>";
        strHtml += "<div class='comment-content-right'>";
        strHtml += "<img width='50' height='50' alt='" + objComment.dsComment[i].nickname + "' src='" + objComment.dsComment[i].avatar + "' />";

        if (flag == 1) {
            strHtml += "<em class='title-avatar nhommua'></em>";
        }
        else if (flag == 2) {
            strHtml += "<em class='title-avatar doitac'></em>";
        }
        else if (flag == 3 && parseInt(objComment.dsComment[i].rankid) >= 4) {
            switch (objComment.dsComment[i].nmrankcate) {
                case "1":
                    strHtml += "<em class='title-avatar dulich'></em>";
                    break;
                case "2":
                    strHtml += "<em class='title-avatar anuong'></em>";
                    break;
                case "3":
                    strHtml += "<em class='title-avatar muasam'></em>";
                    break;
                case "4":
                    strHtml += "<em class='title-avatar giaoduc'></em>";
                    break;
                case "5":
                    strHtml += "<em class='title-avatar cream'></em>";
                    break;
                case "6":
                    strHtml += "<em class='title-avatar giaitri'></em>";
                    break;
                case "7":
                    strHtml += "<em class='title-avatar lamdep'></em>";
                    break;
                case "8":
                    strHtml += "<em class='title-avatar nhakhoa'></em>";
                    break;
                case "10":
                    strHtml += "<em class='title-avatar sanpham'></em>";
                    break;
            }
        }
        //End 28.12.1
        strHtml += "</div>";
        strHtml += "<div class='clear'></div>";
        strHtml += "</div>";
        strHtml += "<div id='divSubComment_" + objComment.dsComment[i].idcomment + "' style='display:none'></div>";
    }
    $("ulComment").innerHTML = strHtml;
    if ($("btnSend")) $("btnSend").onclick = sendCommentDeal;
}
//xử lý hiển thị sub-comment cho comment được chọn
var strIDCommentSP = '';
function showSubCommentSP(iIDComment) {
    if ($("divSubComment_" + iIDComment).style.display == "block") {
        $("divSubComment_" + iIDComment).style.display = "none";
    } else {
        strIDCommentSP = iIDComment;
        var strUrlLocation = window.location.href;
        strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            strUrlLink = strPathLink_All + "yahoo/";
        }
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            utils.call(strUrlLink + "nhommua/deal_comments.aspx", { "flag": "showsub", "id": iIDComment }, "POST", "showSubCommentSPResult", "showSubCommentSPResult");
        } else {
            utils.call(strUrlLink + strStateNM + "/nhommua/deal_comments.aspx", { "flag": "showsub", "id": iIDComment }, "POST", "showSubCommentSPResult", "showSubCommentSPResult");
        }
    }
}
//xử lý check sub-comment nhập trong trạng thái chưa login
function checkSubComment() {
    if (GetCookie("txtSubComment") != null && GetCookie("txtSubComment") != "") {
        var CommentID = GetCookie("CommentID");
        showSubCommentSP(CommentID);
    };
}
//xử lý kết quả trả về sau khi yêu cầu sub-comment
function showSubCommentSPResult(obj) {

    var strUrlLocation = window.location.href;
    strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        strUrlLink = strPathLink_All + "yahoo/";
    }

    var strHtml = "";

    if (obj.dsSubComment != "0") {
        for (var i = 0; i < obj.dsSubComment.length; i++) {
            strHtml += "<div class='comment-content short-size'>";
            strHtml += "<div class='detail-deal'>";
            strHtml += "<p>" + obj.dsSubComment[i].noidung + "</p>";
            //19.12.1
            var flag = 0;
            if (obj.dsSubComment[i].idtk == "138503" || obj.dsSubComment[i].idtk == "306400" || obj.dsSubComment[i].idtk == "101450" || obj.dsSubComment[i].idtk == "961214" || obj.dsSubComment[i].idtk == "997623") {
                flag = 1;
            }
            else if (obj.dsSubComment[i].merchantid != "" && parseInt(obj.dsSubComment[i].merchantid) > 0) {
                flag = 2;
            }
            else if (obj.dsSubComment[i].nmrankcate != "0") {
                flag = 3;
            }

            var clas = "user-info ";
            var strNameUser = "";
            // 23.12
            //if (obj.dsSubComment[i].rankid != "0") {
            strNameUser = " - <em>" + obj.dsSubComment[i].rankname + "</em>";
            switch (obj.dsSubComment[i].rankid) {
                case "1":
                    clas += "vip-dif";
                    break;
                case "2":
                    clas += "vip-clo";
                    break;
                case "3":
                    clas += "vip-sim";
                    break;
                case "4":
                    clas += "vip-sil";
                    break;
                case "5":
                    clas += "vip-gol";
                    break;
                case "6":
                    clas += "vip-dia";
                    break;
                default:
                    clas += "vip-dif";
            }
            //}
            //            else {
            //                clas += "vip-dif";
            //            }
            //End 23.12

            //N3.18.11
            if (flag == 1 || flag == 2) {
                strHtml += "<p class='" + clas + "' style='background:none;padding-left:0'>";
                strNameUser = "";
            }
            else {
                strHtml += "<p class='" + clas + "'>";
            }
            //strHtml += "<p class='" + clas + "'>";
            strHtml += "<a href='" + strUrlLink + strStateNM + "/profile/comments.aspx?mid=" + obj.dsSubComment[i].idtk + (strLangNM == "en" ? "&lang=en" : "") + "' name=''>" + obj.dsSubComment[i].nickname + "</a>";
            strHtml += strNameUser + "<span>" + obj.dsSubComment[i].tgtao + "</span></p>";
            strHtml += "</div>";
            strHtml += "<i></i>";
            strHtml += "<div class='comment-content-right'>";
            strHtml += "<a href='" + strUrlLink + strStateNM + "/profile/comments.aspx?mid=" + obj.dsSubComment[i].idtk + (strLangNM == "en" ? "&lang=en" : "") + "' style='height:50px;width:50px;display:block'>";
            strHtml += "<img width='50' height='50' src='" + obj.dsSubComment[i].avatar + "'/>";
            strHtml += "</a>";
            //N3.18.11 end

            if (flag == 1) {
                strHtml += "<em class='title-avatar nhommua'></em>";
            }
            else if (flag == 2) {
                strHtml += "<em class='title-avatar doitac'></em>";
            }
            // 26.12
            else if (flag == 3 && parseInt(obj.dsSubComment[i].rankid) >= 4) {
                // End 26.12
                switch (obj.dsSubComment[i].nmrankcate) {
                    case "1":
                        strHtml += "<em class='title-avatar dulich'></em>";
                        break;
                    case "2":
                        strHtml += "<em class='title-avatar anuong'></em>";
                        break;
                    case "3":
                        strHtml += "<em class='title-avatar muasam'></em>";
                        break;
                    case "4":
                        strHtml += "<em class='title-avatar giaoduc'></em>";
                        break;
                    case "5":
                        strHtml += "<em class='title-avatar cream'></em>";
                        break;
                    case "6":
                        strHtml += "<em class='title-avatar giaitri'></em>";
                        break;
                    case "7":
                        strHtml += "<em class='title-avatar lamdep'></em>";
                        break;
                    case "8":
                        strHtml += "<em class='title-avatar nhakhoa'></em>";
                        break;
                    case "10":
                        strHtml += "<em class='title-avatar sanpham'></em>";
                        break;
                }
            }
            strHtml += "</div>";
            strHtml += "<div class='clear'></div>";
            strHtml += "</div>";
            //End 19.12.1
        }

        //N4.18.11
        $("subCount_" + obj.IDComm).innerHTML = obj.dsSubComment.length + " " + (strLangNM == "en" ? "comments" : "lời bình");
        //N4.18.11 end
    }
    else
        $("subCount_" + obj.IDComm).innerHTML = (strLangNM == "en" ? "0 comments" : "0 lời bình");

    strHtml += "<div class='comment-content-alignright'>";
    strHtml += "<textarea class='textareaCP' id='txtSubComment_" + obj.IDComm + "' ></textarea>";

    //N5.18.11
    strHtml += "<p><a class='" + (strLangNM == "en" ? "view-button-en" : "view-button") + "' name='" + obj.IDComm + "' href='javascript:void(0)' onclick='insertSubComment(this.name);' id='btnSub_" + obj.IDComm + "' ></a></p>";
    //N5.18.11 end

    strHtml += "<div class='clear'></div>";
    strHtml += "</div>";
    $("divSubComment_" + obj.IDComm).style.display = "block";
    $("divSubComment_" + obj.IDComm).innerHTML = strHtml;
    $("txtSubComment_" + obj.IDComm).focus();

    if (GetCookie("txtSubComment") != "undefine" || GetCookie("txtSubComment") != "") {
        var txtSubComment = GetCookie("txtSubComment");
        var txtSubCommentID = GetCookie("txtSubCommentID");
        $(txtSubCommentID).value = txtSubComment;
    };
}
//xử lý insert sub-comment
function insertSubComment(idComment) {
    if ($("txtSubComment_" + idComment).value.length > 0) {
        var strUrlLocation = window.location.href;
        strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            strUrlLink = strPathLink_All + "yahoo/";
        }
        if (objLogin != null) {

            DeleteCookie("txtSubComment", "");
            DeleteCookie("txtSubCommentID", "");
            DeleteCookie("CommentID", "");

            var strContent = $("txtSubComment_" + idComment).value;
            $("txtSubComment_" + idComment).value = "";
            strIDCommentSP = idComment;
            if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
                utils.call(strUrlLink + "nhommua/deal_comments.aspx", { "flag": "insertsub", "id": idComment, "idtp": "8", "desc": strContent }, "POST", "showSubCommentSPResult", "showSubCommentSPResult");
            } else {
                utils.call(strUrlLink + strStateNM + "/nhommua/deal_comments.aspx", { "flag": "insertsub", "id": idComment, "idtp": "8", "desc": strContent }, "POST", "showSubCommentSPResult", "showSubCommentSPResult");
            }

        } else {
            if ($("txtSubComment_" + idComment).value.length > 0) {
                SetCookie("txtSubComment", $("txtSubComment_" + idComment).value, 60);
                SetCookie("txtSubCommentID", "txtSubComment_" + idComment, 60);
                SetCookie("CommentID", idComment, 60);
            }

            //N6.18.11
            window.open(strUrlLink + strStateNM + "/login.aspx" + (strLangNM == "en" ? "?lang=en" : ""), "_self");
            //N6.18.11 end
        }
    }
}

/********************************************************************************************************/
var iCurrentReferrer = 1;
function showLisrReferrer() {

    var strUrlLocation = window.location.href;
    strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        strUrlLink = strPathLink_All + "yahoo/";
    }

    iEnd = 0;
    iStart = 0;
    var iCount = objRefer.dsRefer.length - 1;
    iTotal = Math.ceil(iCount / 10);
    iStart = iCurrentReferrer * 10 - 10;
    iEnd = iStart + 10;
    iEnd = iEnd > iCount ? iCount : iEnd;

    if (objRefer.dsRefer != "0") {

        var strHTML = "";

        //N7.18.11
        /*********************************************/
        strHTML += '<div class="title_trans">';
        strHTML += '<h3>' + (strLangNM == "en" ? langRefer_en()[0][22] : langRefer()[0][22]) + '</h3></div>' +
                               ' <div class="deal_content">' +
                                	'<p style="padding: 5px 0 5px 0; font-size:13px; color:#fff;">' + (strLangNM == "en" ? langRefer_en()[0][17] : langRefer()[0][17]) + '</p>' +
                                   ' <span style="float:left;padding:15px 4px 0 0; font-size:13px; color:#fff;">- ' + (strLangNM == "en" ? langRefer_en()[0][2] : langRefer()[0][2]) + ' </span>' +
                                    '<div class="div_txtSI">' +
                                    '	<input type="text" id="txtMaRefer" value="' + objRefer.dsRefer[iCount].total + '" readonly="false"  />' +
                                  '  </div>' +
                                   ' <span style="float:left;padding:15px 0 0 4px;width:45px; font-size:13px; color:#fff;"> ' + (strLangNM == "en" ? langRefer_en()[0][3] : langRefer()[0][3]) + '</span>' +
                                    '<i class="iLineWinNoki"></i>' +
                                  ' <p style="padding-top:10px; padding-bottom: 5px;font-size:12px; color:#fff;">' + (strLangNM == "en" ? langRefer_en()[0][4] : langRefer()[0][4]) + '</p>' +
                                   ' <div class="bg-email-deal" style="margin: 0;">' +
                                    	'<span class="bg-email-input" ><input type="text" value="' + strUrlLink + strStateNM + '/?refer=' + objRefer.dsRefer[iCount].id + '&id=' + strDeal.id + '" id="txtLinkReferre" /></span>' +
                                      '  <span class="bg-email-btn" style="text-align:center;" onclick="javascript:selectTextbox()"><em style=" padding-left:0;font-size: 12px;">' + (strLangNM == "en" ? langRefer_en()[0][5] : langRefer()[0][5]) + '</em></span>' +
                                   ' </div> ' +
                                   ' <div class="div_ChiaSe">' +
                                    	'<p style="font-size: 12px;height: 18px;padding: 7px 3px 0 0; float:left; color:#333333;"><strong>' + (strLangNM == "en" ? langRefer_en()[0][18] : langRefer()[0][18]) + '</strong></p>' +
                                        '<div class="div_iconYahooMail">' +
                                        	'<a href="http://www.facebook.com/sharer.php?u=' + escape(strUrlLink + strStateNM + '/?refer=' + objRefer.dsRefer[iCount].id) + '&id=' + strDeal.id + '" class="aFaceBook" target="_blank"></a>' +
                                       '</div>' +
                                       '<div class="div_iconYahooMail">' +
                                       		'<a href="ymsgr:im?+&msg=' + langRefer()[0][16] + ' - ' + strUrlLink + strStateNM + '/?refer=' + objRefer.dsRefer[iCount].id + '&id=' + strDeal.id + '" class="aYahooChat"></a>' +
                                      '</div>' +
                                    '</div>  ' +
                                    '<div class="list-email">';

        for (var i = iStart; i < iEnd; i++) {
            strHTML += '<p>' + (i + 1) + '. <strong>' + (objRefer.dsRefer[i].email.length > 13 ? objRefer.dsRefer[i].email.substring(0, 13) + "..." : objRefer.dsRefer[i].email) + '</strong> _ MS:<strong>' + objRefer.dsRefer[i].ma + '</strong></p>';
        }

        strHTML += '</div>' +
                                    '<div class="small-paging">' +
                                        '<div class="paging-gray-half">' +
                                            '<p>	';
        if (iTotal > 1) {

            if (iCurrentReferrer > 1) {
                strHTML += '<a onclick="pagingRefer(' + (iCurrentReferrer - 1) + ')" href="javascript:void(0)"><</a>';
            }
            for (var i = 0; i < iTotal; i++) {

                strHTML += '<a onclick="pagingRefer(' + (i + 1) + ')" style="' + (iCurrentReferrer == (i + 1) ? 'color:#00ccff' : '') + '" href="javascript:void(0)">' + (i + 1) + '</a>';

            }
            if (iCurrentReferrer < iTotal) {
                strHTML += '<a onclick="pagingRefer(' + (iCurrentReferrer + 1) + ')" href="javascript:void(0)">></a>';
            }
        }
        strHTML += '</p>   ' +
                                        '</div>' +
                                    '</div>' +
                                '</div>';
        /************************************************/
        $("divReferrer").innerHTML = strHTML;
        $("divReferrer").style.display = "block";

        //N7.18.11 end
    }
    else {

        $("divReferrer").style.display = "none";
    }

}
/******************************************************************************************/
function pagingRefer(ipage) {
    var iCount = objRefer.dsRefer.length - 1;
    iTotal = Math.ceil(iCount / 10);
    iCurrentReferrer = ipage <= 0 ? 1 : (ipage > iTotal ? iTotal : ipage);
    showLisrReferrer();
}

function selectTextbox() {
    $("txtLinkReferre").select();
}

/******************************************************************************************/
var api = null;
//Edit 17/01/2013
function loadMap() {
    if (isMapApi == 'True') {
//        api = new EBMap("dMap", 605, 299);
//        api.clickLogo(true);
//        api.uInfBox();
//        api.setLogo("http://www.nhommua.com.vn/images/iconMap.png", 45, 46);
//        api.initAPI();
//        api.aZoom = new Array(0.0244, 0.0488, 0.0976, 0.1953, 0.3906,
//    0.7812, 1.5625, 3.125, 6.25, 12.5, 25, 50, 100);

//        api.addTypeControl(MAP_POS_RIGHTTOP, 20, 20);
//        api.addZoomControl(20, 20);
//        api.showCompany(result);
        api = new GoogleMap("dMap", 605, 299);
        api.addListPoint(result.dsCompany);
    }
}
/******************************************************************************************/

function showPopupSP() {

    var wdListSP = 0;
    var countItem = $("dList_SP").select("div.item").length;
    if (countItem >= 3) {
        //wdListSP = 769;
		wdListSP = 770;
        $("dList_SP").setStyle({ width: wdListSP + "px" });
        $("dList_SP").select("div.cont-popup")[0].setStyle({ width: (wdListSP - 10 * 3) + "px" });
        $("dList_SP").select("p")[0].setStyle({ width: (wdListSP + 2) + "px" });
        //$("dList_SP").select("ul")[0].setStyle({ width: Math.ceil(countItem / 3) * wdListSP + "px" });
        $("dList_SP").select("ul")[0].setStyle({ height: "217px" });
    }
    else {
        wdListSP = 769 - Math.floor((3 - countItem) * (769 / 3));
        $("dList_SP").setStyle({ width: wdListSP + "px" });
        $("dList_SP").select("div.cont-popup")[0].setStyle({ width: (wdListSP - 10 * countItem) + "px" });
        $("dList_SP").select("p")[0].setStyle({ width: (wdListSP + 10 * (3 - countItem) + 2 * (3 - countItem)) + "px" });
    }


    setPopUpCenter("dList_SP");
    $("dList_SP").style.display = "block";
    $("dShadow").style.display = "block";

    eventPopupSP();

}


var slItem = 0;
var slCurr = 0;
var strPAID = "";
function eventPopupSP() {

    if ($("dList_SP")) {
        //khi click to image cua san pham
        var argImgItem = $("dList_SP").select("div.item");
        for (var i = 0; i < argImgItem.length; i++) { $(argImgItem[i]).onclick = setStatusSelectItem_PopupSP; }

        //khi click to checkbox cua san pham
        var argCheckItem = $("dList_SP").select("label");
        for (var i = 0; i < argCheckItem.length; i++) {
            $(argCheckItem[i]).onclick = setStatusSelectItem_PopupSP;
        }

        //khi chon so luong cua san pham
        var argSLItem = $("dList_SP").select("select");
        for (var i = 0; i < argSLItem.length; i++) {
            $(argSLItem[i]).onchange = setStatusSelectItem_PopupSP;
            $(argSLItem[i]).onclick = setSLCurr;
        }
        //khi click Mua
        if ($("btnMua_PopupSP")) {
            $("btnMua_PopupSP").onclick = submitMuaPopupSP;
        }
        //next-preview
        var objPre = $("dList_SP").select("span.desc-prev")[0];
        var objNext = $("dList_SP").select("span.desc-next")[0];
        if (argImgItem.length > 3) {
            $(objPre).onclick = NextPreviewPopupSP;
            $(objNext).onclick = NextPreviewPopupSP;
        } else {
            $(objPre).style.display = "none";
            $(objNext).style.display = "none";
        }
        try {
            if (arrPAID) {
                for (var i = 0; i < arrPAID.length; i++) {
                    var PAID = arrPAID[i].split('_')[0];
                    var SL = arrPAID[i].split('_')[1];
                    $("PAID_" + PAID).value = SL;

                    /*add 8.12*/
                    var element = $("PAID_" + PAID).up('li', 0);
                    $(element.select("label")[0]).removeClassName("notchecked");
                    $(element.select("label")[0]).addClassName("checked");
                    $(element.select("input")[0]).checked = true;
                    /*add 8.12 end*/
                }
            }
        } catch (e) { };

    }

}
function NextPreviewPopupSP(e) {

    var element = utils.getElementFireEvent(e);
    var eventTagName = element.nodeName.toLowerCase();
    var isObj = "";
    var wdListSP = 769;
    var pContPopUp = 16;
    var ulPopUp = $("dList_SP").select("ul.ul-popup")[0];
    //var ulPopUp = $("ul-popup-sp");
    var countItem = $("dList_SP").select("div.item").length;

    /*kiem tra la Next hay Preview*/
    if (eventTagName == "em") {
        isObj = $(element).up("span", 0).className == "desc-prev" ? "pre" : "next";
    }
    else {
        isObj = $(element).className == "desc-prev" ? "pre" : "next";
    }
    /*set margin-left trong 2 truong hop Next hoac Preview*/
    var mLeft = (isObj == "pre") ? (($(ulPopUp).positionedOffset()[0] - pContPopUp) + (wdListSP - 2 * pContPopUp)) : (($(ulPopUp).positionedOffset()[0] - pContPopUp) - (wdListSP - 2 * pContPopUp));
    if (isObj == "pre" && mLeft <= 0) {
        $(ulPopUp).setStyle({ marginLeft: mLeft + "px" });
    }
    else if (isObj == "next" && mLeft > -Math.floor(countItem / 3) * wdListSP) {
        $(ulPopUp).setStyle({ marginLeft: mLeft + "px" });
    }
    /*set active Next va Preview*/
    //    if ((isObj == "pre" && mLeft < 0) || (isObj == "next" && mLeft > -(Math.floor(countItem / 3) * wdListSP - wdListSP))) {
    //        $("dList_SP").select("span.desc-prev")[0].select("em")[0].addClassName("active");
    //        $("dList_SP").select("span.desc-next")[0].select("em")[0].addClassName("active");  
    //    }
    //    else {
    //        if (eventTagName == "em") {
    //            $(element).removeClassName("active");
    //        }
    //        else {
    //            $(element).select("em")[0].removeClassName("active");
    //        }
    //    }


    




    //hidden va visible cac the li
    var groupActive = -(mLeft / 737);
    groupActive = groupActive < 0 ? 0 : groupActive > Math.floor(countItem / 3) ? Math.floor(countItem / 3) : groupActive;
    var argLi = $(ulPopUp).select("li");
    for (var i = 0; i < argLi.length; i++) {

        if (i >= (6 * groupActive) && i < (6 * (groupActive + 1) - 1)) {
            $(argLi[i]).style.visibility = "visible";
        }
        else {
            $(argLi[i]).style.visibility = "hidden";
        }
    }
    //24.5
    if (isObj == "next" && mLeft < 0) {
        $("dList_SP").select("span.desc-prev")[0].select("em")[0].addClassName("active");
    }
    else {
        if (argLi.length > 0 && ($(argLi)[argLi.length - 1].style.visibility == "visible" || $(argLi)[0].style.visibility == "visible")) {
            if (eventTagName == "em") {
                $(element).removeClassName("active");
            }
            else {
                $(element).select("em")[0].removeClassName("active");
            }
        }
    }
    if (isObj == "pre" && mLeft > -(Math.ceil(countItem / 3) * wdListSP - wdListSP)) {
        $("dList_SP").select("span.desc-next")[0].select("em")[0].addClassName("active");
    }
    else {
        if (argLi.length > 0 && ($(argLi)[argLi.length - 1].style.visibility == "visible" || $(argLi)[0].style.visibility == "visible")) {
            if (eventTagName == "em") {
                $(element).removeClassName("active");
            }
            else {
                $(element).select("em")[0].removeClassName("active");
            }
        }
    }

}
//set so luong hien tai truoc khi thay doi so luong
function setSLCurr(e) {
    var element = utils.getElementFireEvent(e).up('li', 0);
    slCurr = $(element.select("select")[0]).value;
    return false;
}

function setStatusSelectItem_PopupSP(e) {
    var element = utils.getElementFireEvent(e).up('li', 0);
    var tagEvent = utils.getElementFireEvent(e);

    //truong hop click image hoac checkbox
    if ($(tagEvent).nodeName.toLowerCase() != "select") {

        if ($(element.select("input")[0]).checked) {

            $(element.select("label")[0]).removeClassName("checked");
            $(element.select("label")[0]).addClassName("notchecked");
            $(element.select("input")[0]).checked = false;
            $(element.select("select")[0]).value = 0;

        }
        else {
            $(element.select("label")[0]).removeClassName("notchecked");
            $(element.select("label")[0]).addClassName("checked");
            $(element.select("input")[0]).checked = true;

            slCurr = $(element.select("select")[0]).value;
            if ($(element.select("select")[0]).value == 0) {
                $(element.select("select")[0]).value = 1;

            }
        }
    }
    //truong hop chon so luong
    else {

        if ($(element.select("select")[0]).value == 0) {
            $(element.select("label")[0]).removeClassName("checked");
            $(element.select("label")[0]).addClassName("notchecked");
            $(element.select("input")[0]).checked = false;

        }
        else {
            $(element.select("label")[0]).removeClassName("notchecked");
            $(element.select("label")[0]).addClassName("checked");
            $(element.select("input")[0]).checked = true;
        }
    }

    //kiem tra tong so luong sau khi chon
    slItem = getTongSL();
    if (slItem > strDeal.SLMua) {

        alert("Tổng số lượng tối đa bạn có thể mua cho sản phẩm này là " + strDeal.SLMua.toString());
        $(element.select("select")[0]).value = slCurr;
        if ($(element.select("select")[0]).value == 0) {
            $(element.select("label")[0]).removeClassName("checked");
            $(element.select("label")[0]).addClassName("notchecked");
            $(element.select("input")[0]).checked = false;
        }
        else {
            if (slCurr == 0) {
                $(element.select("label")[0]).removeClassName("checked");
                $(element.select("label")[0]).addClassName("notchecked");
                $(element.select("input")[0]).checked = false;
            }
            else {
                $(element.select("label")[0]).removeClassName("notchecked");
                $(element.select("label")[0]).addClassName("checked");
                $(element.select("input")[0]).checked = true;
            }
        }

    }
    return false;
}
//lay tong so luong
function getTongSL() {

    strPAID = "";
    slItem = 0;
    var SL = 0;
    var PAID = "";
    var argSLItem = $("dList_SP").select("select");
    for (var i = 0; i < argSLItem.length; i++) {
        SL = parseInt($(argSLItem[i]).value);
        PAID = $(argSLItem[i]).id.replace("PAID_", "");
        if (SL != 0) {
            slItem += SL;
            /*strPAID += (strPAID == "") ? (PAID + "_" + SL.toString()) : (";" + PAID + "_" + SL.toString());*/
            strPAID += PAID + "_" + SL.toString() + ";";
        }
    }
    return slItem;
}

function submitMuaPopupSP(e) {

    slItem = getTongSL();
    if (slItem == 0) {
        //alert("Bạn chưa chọn số lượng đặt hàng");
        alert("Tổng số lượng tối thiểu bạn cần mua cho sản phẩm này là " + strDeal.SLMua_ToiThieu.toString()); // 31.5.12
    }
    else {
        var strUrlLocation = window.location.href;
        strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            strUrlLink = strPathLink_All + "yahoo/";
        }
        /*
        if (slItem <= strDeal.SLMua) {
            utils.call(strUrlLink + strStateNM + "/buy-deals.aspx", { "flag": "SPYeuThich", "id": strDeal.id, "strPAID": strPAID }, "POST", "resultSPYeuThich", "resultSPYeuThich");
        }
        else {
            alert("Tổng số lượng tối đa bạn có thể mua cho sản phẩm này là " + strDeal.SLMua.toString());
        }
        */
        // 31.5.12
        if (slItem < strDeal.SLMua_ToiThieu) {
            alert("Tổng số lượng tối thiểu bạn cần mua cho sản phẩm này là " + strDeal.SLMua_ToiThieu.toString());
        }
        else if (slItem > strDeal.SLMua) {
            alert("Tổng số lượng tối đa bạn có thể mua cho sản phẩm này là " + strDeal.SLMua.toString());
        }
        else {
            utils.call(strUrlLink + strStateNM + "/buy-deals.aspx", { "flag": "SPYeuThich", "id": strDeal.id, "strPAID": strPAID }, "POST", "resultSPYeuThich", "resultSPYeuThich");
        }
        // End 31.5.12

    }
    return false;
}
function resultSPYeuThich(strResult) {
    var strUrlLocation = window.location.href;
    strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        strUrlLink = strPathLink_All + "yahoo/";
    }
    if (strResult == "1") {

        if (strStateNM == "ha-noi") {
            window.location.href = strUrlLink + strStateNM + "/buy-deals-hn.aspx?id=" + strDeal.id + "&st=" + strStateNM + (strLangNM == "en" ? "&lang=en" : "");
        }
        else {
            window.location.href = strUrlLink + strStateNM + "/buy-deals.aspx?id=" + strDeal.id + "&st=" + strStateNM + (strLangNM == "en" ? "&lang=en" : "");
        }


    }
    else if (strResult == "0") {
        window.location.href = strUrlLink + strStateNM + "/login-buy.aspx?id=" + strDeal.id + (strLangNM == "en" ? "&lang=en" : "");
    }
}


function eventGioThieuSanPham() {
    var objParent = $("dListSP_GioiThieu");
    var wdListSP = 0;
    var countItem = objParent.select("div.item").length;
    wdListSP = 450;
    objParent.setStyle({ width: wdListSP + "px" });
    objParent.select("ul")[0].setStyle({ height: "178px" });

    var ulPopUp = objParent.select("ul.ul-popup")[0];
    $(ulPopUp).setStyle({ width: (wdListSP + 16) * Math.ceil(countItem / 2) + "px" });

    var objPre = objParent.select("span.desc-prev")[0];
    var objNext = objParent.select("span.desc-next")[0];
    if (countItem > 2) {
        //next-preview        
        $(objPre).onclick = NextPreviewGioThieuSanPham;
        $(objNext).onclick = NextPreviewGioThieuSanPham;
    }
    else {
        $(objPre).style.display = "none";
        $(objNext).style.display = "none";
    }
}
function NextPreviewGioThieuSanPham(e) {

    var element = utils.getElementFireEvent(e);
    var eventTagName = element.nodeName.toLowerCase();
    var objParent = $("dListSP_GioiThieu");
    var isObj = "";
    var wdListSP = 456;
    var pContPopUp = 16;
    var ulPopUp = objParent.select("ul.ul-popup")[0];
    var countItem = objParent.select("div.item").length;

    /*kiem tra la Next hay Preview*/
    if (eventTagName == "em") {
        isObj = $(element).up("span", 0).className == "desc-prev" ? "pre" : "next";
    }
    else {
        isObj = $(element).className == "desc-prev" ? "pre" : "next";
    }

    /*set margin-left trong 2 truong hop Next hoac Preview*/
    var mLeft = (isObj == "pre") ? (($(ulPopUp).positionedOffset()[0] - pContPopUp) + wdListSP) : (($(ulPopUp).positionedOffset()[0] - pContPopUp) - wdListSP);
    if (isObj == "pre" && mLeft <= 0) {
        $(ulPopUp).setStyle({ marginLeft: mLeft + "px" });
    }
    else if (isObj == "next" && mLeft > -Math.ceil(countItem / 2) * wdListSP) {
        $(ulPopUp).setStyle({ marginLeft: mLeft + "px" });
    }

    

    //hidden va visible cac the li
    var groupActive = -(mLeft / 456);
    groupActive = groupActive < 0 ? 0 : groupActive > Math.ceil(countItem / 2) - 1 ? Math.ceil(countItem / 2) - 1 : groupActive;

    var argLi = $(ulPopUp).select("li");
    for (var i = 0; i < argLi.length; i++) {

        if (i >= (2 * groupActive) && i < (2 * (groupActive + 1))) {
            $(argLi[i]).style.visibility = "visible";
        }
        else {
            $(argLi[i]).style.visibility = "hidden";
        }
    }
    //24.5
    /*set active Next va Preview*/
    if (isObj == "next" && mLeft < 0) {
        objParent.select("span.desc-prev")[0].select("em")[0].addClassName("active");
    }
    else {
        if (argLi.length > 0 && ($(argLi)[argLi.length - 1].style.visibility == "visible" || $(argLi)[0].style.visibility == "visible")) {
            if (eventTagName == "em") {
                $(element).removeClassName("active");
            }
            else {
                $(element).select("em")[0].removeClassName("active");
            }
        }
    }
    if (isObj == "pre" && mLeft > -(Math.ceil(countItem / 2) * wdListSP - wdListSP)) {
        objParent.select("span.desc-next")[0].select("em")[0].addClassName("active");
    }
    else {
        if (argLi.length > 0 && ($(argLi)[argLi.length - 1].style.visibility == "visible" || $(argLi)[0].style.visibility == "visible")) {
            if (eventTagName == "em") {
                $(element).removeClassName("active");
            }
            else {
                $(element).select("em")[0].removeClassName("active");
            }
        }
    }
}
/* 16.4.12 */
function PressKeyEmailDetail(e) {
    var evt = e ? e : window.event;
    var bt = $(this.id);
    if (bt) {
        if (evt.keyCode == "13" || evt.which == "13" || evt.charCode == "13") {
            try { bt.click(); } catch (e) { }
            switch (this.id) {
                case "txtEmailDetail":
                    SendEmailNhanGiaTotDetail();
                    break;
            }
            return false;
        }
    }
}
function SendEmailNhanGiaTotDetail() {
    if (checkMail($("txtEmailDetail").value) == true) {
        if ($("btnSendMailSameDeal")) {
            $("btnSendMailSameDeal").onclick = "";  //insertEmailNhanGiaTot;
        }
        var strUrlLocation = window.location.href;
        strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            strUrlLink = strPathLink_All + "yahoo/";
        }
        utils.call(strUrlLink + strStateNM + "/gia-tot-hom-nay.html", { "flag": "InsertEmailNhanGiaTot", "email": $("txtEmailDetail").value, "city": $('ddlEmailDetail').value }, "POST", "insertEmailDetailResult", "insertEmailDetailResult");
    }
    else {
        var msg = (utils.trim($('txtEmailDetail').value) == "") ? "Bạn chưa nhập địa chỉ email" : "Email của bạn không đúng định dạng";
        try {
            showErrorRegister('msgError', 'false', msg, 'block');
            if ($("pError")) {
                $("pError").setStyle({
                    marginBottom: "15px"
                });
            }
        }
        catch (e) {

        }
    }
};

function insertEmailDetailResult(str) {
    if ($('btnSendMailSameDeal')) {
        $('btnSendMailSameDeal').onclick = SendEmailNhanGiaTotDetail;
    }
    if ($('txtEmailDetail')) {
        $('txtEmailDetail').value = "";
    }
    try {
        if (parseInt(str) == 1) {
            showErrorRegister('msgError', 'true', (strLangNM == "en" ? langMess_en()[0][27] : langMess()[0][27]), 'block');
            if ($("pError")) {
                $("pError").setStyle({
                    marginBottom: "15px"
                });
            }
        } else {
            showErrorRegister('msgError', 'false', (strLangNM == "en" ? langMess_en()[0][26] : langMess()[0][27]), 'block');
            if ($("pError")) {
                $("pError").setStyle({
                    marginBottom: "15px"
                });
            }
        }
    }
    catch (e) {
        //alert("Email của bạn đã cập nhật thành công")
    }
}

function onChangeCitiesDetail(id, value) {
    var selectedValue = value;
    $('ddlEmailDetail_SV').innerHTML = value; //edit here 28/02 2:12PM
};
// 2.5.12
function showPopUpRedeal() {
    var dRedeal = $("dRedeal");
    if (dRedeal.select("div.bg-box").length > 0) {
        if (dRedeal) {
            if (dRedeal.style.display == "none") {
                setPopUpCenter("dRedeal");
                $("dShadow").style.display = "block";
                dRedeal.show();

                if ($("sMessRedeal")) {
                    $("sMessRedeal").innerHTML = "";
                }
            }
            else {
                dRedeal.hide();
                $("dShadow").hide();
            }
            if ($("closeRedeal")) {
                $("closeRedeal").onclick = closePopupRedeal;
            }
        }
    }
}
function closePopupRedeal() {    
    $("dRedeal").style.display = "none";
    $("dShadow").style.display = "none";
}
function sendMailRedeal() {
    if (checkMail($("redealemail").value) == true) {
        var strUrlLocation = window.location.href;
        strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            strUrlLink = strPathLink_All + "yahoo/";
        }

        utils.call(strUrlLink + strStateNM + "/mua-hang-gia-re.html", { "flag": "insertEmailRedeal", "email": $("redealemail").value, "city": strStateNM, "idCate": idCate, "idSubCate": idSubCate, "idSPGC": idSPGC }, "POST", "insertEmailRedealResult", "insertEmailRedealResult");
    }
    else {
        var msg = (utils.trim($('redealemail').value) == "") ? "Bạn chưa nhập địa chỉ email" : "Email của bạn không đúng định dạng";
        if ($("sMessRedeal")) {
            $("sMessRedeal").innerHTML = msg;
        }
        else {
            alert(msg);
        }
    }


}
function insertEmailRedealResult(obj) {
    try {
        if ($("dRedeal")) {
            $("dRedeal").style.display = "none";
            $("dShadow").style.display = "none";
        }
        if (parseInt(obj) == 1) {
            showErrorRegister('msgError', 'true', (strLangNM == "en" ? langMess_en()[0][26] : langMess()[0][26]), 'block');
        } else {
            showErrorRegister('msgError', 'false', (strLangNM == "en" ? langMess_en()[0][27] : langMess()[0][27]), 'block');
        }
    }
    catch (e) {
        //alert("Email của bạn đã cập nhật thành công")
    }
}
//End 2.5.12
/**************************Ham xy ly doi ngon ngu trang detail********************************/
function changeDetail_Lang() {
    var lang = isViewLang_Details == "vn" ? "en" : "vn";
    SetCookie("viewLang", lang, 60);
    window.location.reload();
}
//22/01/2013
/***************************Ham xu ly doi trang ma trung thuong*******************************/
function changePageMDT(e) {
    var ele = Event.element(e);
    switch (ele.id) {
        case "aNextMDT":
            curPageMDT = parseInt(curPageMDT) + 1;
            break;
        case "aPreMDT":
            curPageMDT = parseInt(curPageMDT) - 1;
            break;
        default:
            curPageMDT = ele.id.split('_')[1];
            break;
    }
    //$('dListMDT').innerHTML = "<img src='http://localhost:50606/NhomMuaV4/images_v4/ajax-loader1.gif' style='margin:70px 120px;'>";
    $('dListMDT').innerHTML = "<img src='http: //www.mjgroup.com.vn/tp-ho-chi-minh/images_v4/ajax-loader1.gif' style='margin:80px 105px;'>";
    var strUrlLocation = window.location.href;
    strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        strUrlLink = strPathLink_All + "yahoo/";
    }
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        utils.call(strUrlLink + "nhommua/deal_detail_new.aspx", { "flag": "changePageMDT", "page": curPageMDT, "city": strStateNM }, "POST", "changePageMDTResult", "changePageMDTResult");
    }
    else {
        utils.call(strUrlLink + strStateNM + "/nhommua/deal_detail_new.aspx", { "flag": "changePageMDT", "page": curPageMDT, "city": strStateNM }, "POST", "changePageMDTResult", "changePageMDTResult");
        //utils.call("http://localhost:50606/nhommua/deal_detail_new.aspx", { "flag": "changePageMDT", "page": curPageMDT, "city": strStateNM}, "POST", "changePageMDTResult", "changePageMDTResult");
    }
}
function changePageMDTResult(str) {
    if (str != "") {
        $('dListMDT').innerHTML = str;
        var strPaging = "";
        strPaging += "<div class='paging-gray-half'>" +
                        "<p>";
        if (totalPageMDT > 1) {
            strPaging += "<i>Trang: </i>";
            if (curPageMDT > 1) {
                strPaging += "<a id='aPreMDT' href='javascript:void(0);' class='paging-pre'><em></em></a>";
            }
            var iStart = 0;
            var iEnd = 0;
            iStart = curPageMDT - 3;
            iStart = iStart <= 1 ? 1 : iStart;
            iEnd = iStart + 4 >= totalPageMDT ? totalPageMDT : iStart + 4;
            for (var i = iStart; i <= iEnd; i++) {
                if (i == curPageMDT) {
                    strPaging += "<span>" + i + "</span>";
                }
                else {
                    strPaging += "<a id='aMDT_" + i + "' href='javascript:void(0);'>" + i + "</a>";
                }
            }
            if (curPageMDT < totalPageMDT) {
                strPaging += "<a id='aNextMDT' href='javascript:void(0);' class='paging-next'><em></em></a>";
            }
        }
        //end inner paging
        strPaging += "</p>";
        strPaging += "</div>";
        $('dPagingMDT').innerHTML = strPaging;
        if ($('dPagingMDT')) {
            $('dPagingMDT').select('a').invoke('observe', 'click', changePageMDT);
        }
    }
    else {
        $('dListRewardCode').style.display = "none";
    }
}
/*****************************Ham xu ly popup tham gia*********************************/
function joinRewardDeal() {
    var strUrlLocation = window.location.href;
    strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        strUrlLink = strPathLink_All + "yahoo/";
    }
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        utils.call(strUrlLink + "nhommua/deal_detail_new.aspx", { "flag": "showPopupRewardDeal", "city": strStateNM, "idsp": specDealID, "link": specDealLink }, "POST", "joinRewardDealResult", "joinRewardDealResult");
    }
    else {
        utils.call(strUrlLink + strStateNM + "/nhommua/deal_detail_new.aspx", { "flag": "showPopupRewardDeal", "city": strStateNM, "idsp": specDealID, "link": specDealLink }, "POST", "joinRewardDealResult", "joinRewardDealResult");
        //utils.call("http://localhost:50606/nhommua/deal_detail_new.aspx", { "flag": "showPopupRewardDeal", "city": strStateNM, "idsp": specDealID, "link": specDealLink }, "POST", "joinRewardDealResult", "joinRewardDealResult");
    }
}
function joinRewardDealResult(str) {
    if (str != "") {
        //show popup
        $('dPopupRewardDeal').innerHTML = str;
        setPopUpCenter('dPopupRewardDeal');
        $('dShadow').show();
        $('dPopupRewardDeal').show();
        $('iClosePopup').onclick = function() {
            $('dPopupRewardDeal').hide();
            $('dShadow').hide();
        };
        if ($('dPagingMDT_Popup')) {
            $('dPagingMDT_Popup').select('a').invoke('observe', 'click', changePageMDT_Popup);
        }
        curPageMDT_Popup = 1;
        totalPageMDT_Popup = $('spCountTotalPage_Popup') ? parseInt($('spCountTotalPage_Popup').innerHTML) : 0;
        $('btnJoin_Top').onclick = "javascript:void(0);";
        $('btnJoin_Bot').onclick = "javascript:void(0);";
        $('btnJoin_Top').className = "btnRule";
        $('btnJoin_Bot').className = "btnRule-big";
        $('btnJoin_Top').href = specDealLink;
        $('btnJoin_Bot').href = specDealLink;
        $('btnJoin_Top').target = $('btnJoin_Bot').target = "_blank";
    }
}
function changePageMDT_Popup(e) {
    var ele = Event.element(e);
    switch (ele.id) {
        case "aNextMDT_Popup":
            curPageMDT_Popup = parseInt(curPageMDT_Popup) + 1;
            break;
        case "aPreMDT_Popup":
            curPageMDT_Popup = parseInt(curPageMDT_Popup) - 1;
            break;
        default:
            curPageMDT_Popup = ele.id.split('_')[1];
            break;
    }
    $('dListMDT_Popup').innerHTML = "<img src='http://www.nhommuahotdeals.net/tp-ho-chi-minh/images_v4/ajax-loader1.gif' style='margin:70px 120px;'>";
    var strUrlLocation = window.location.href;
    strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        strUrlLink = strPathLink_All + "yahoo/";
    }
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        utils.call(strUrlLink + "nhommua/deal_detail_new.aspx", { "flag": "changePageMDT_Popup", "city": strStateNM, "idsp": specDealID, "page": curPageMDT_Popup }, "POST", "changePageMDT_PopupResult", "changePageMDT_PopupResult");
    }
    else {
        utils.call(strUrlLink + strStateNM + "/nhommua/deal_detail_new.aspx", { "flag": "changePageMDT_Popup", "city": strStateNM, "page": curPageMDT_Popup}, "POST", "changePageMDT_PopupResult", "changePageMDT_PopupResult");
        //utils.call("http://localhost:50606/nhommua/deal_detail_new.aspx", { "flag": "changePageMDT_Popup", "city": strStateNM, "page": curPageMDT_Popup }, "POST", "changePageMDT_PopupResult", "changePageMDT_PopupResult");
    }
}
function changePageMDT_PopupResult(str) {
    if (str != "") {
        $('dListMDT_Popup').innerHTML = str;
        //inner paging
        var strPaging = "";
        strPaging += "<div class='paging-gray-half'>" +
                        "<p>";
        if (totalPageMDT_Popup > 1) {
            strPaging += "<i>Trang: </i>";
            if (curPageMDT_Popup > 1) {
                strPaging += "<a id='aPreMDT_Popup' href='javascript:void(0);' class='paging-pre'>&#9664</a>";
            }
            var iStart = 0;
            var iEnd = 0;
            iStart = curPageMDT_Popup - 3;
            iStart = iStart <= 1 ? 1 : iStart;
            iEnd = iStart + 4 >= totalPageMDT_Popup ? totalPageMDT_Popup : iStart + 4;
            for (var i = iStart; i <= iEnd; i++) {
                if (i == curPageMDT_Popup) {
                    strPaging += "<span>" + i + "</span>";
                }
                else {
                    strPaging += "<a id='aPopupMDT_" + i + "' href='javascript:void(0);'>" + i + "</a>";
                }
            }
            console.log(curPageMDT_Popup + "_" + totalPageMDT_Popup);
            if (curPageMDT_Popup < totalPageMDT_Popup) {
                strPaging += "<a id='aNextMDT_Popup' href='javascript:void(0);' class='paging-next'>&#9654</a>";
            }
        }
        //end inner paging
        strPaging += "</p>";
        strPaging += "</div>";
        $('dPagingMDT_Popup').innerHTML = strPaging;
        if ($('dPagingMDT_Popup')) {
            $('dPagingMDT_Popup').select('a').invoke('observe', 'click', changePageMDT_Popup);
        }
    }
}
//16/01/2013
/******************************Ham redirect reaward deal***********************/
function redirectRewardDeal() {
    var strUrlLocation = window.location.href;
    strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        strUrlLink = strPathLink_All + "yahoo/";
    }
    if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
        utils.call(strUrlLink + "nhommua/deal_detail_new.aspx", { "flag": "redirectRewardDeal", "detail_link": specDealLink_Detail }, "POST", "redirectRewardDealResult", "redirectRewardDealResult");
    }
    else {
        utils.call(strUrlLink + strStateNM + "/nhommua/deal_detail_new.aspx", { "flag": "redirectRewardDeal", "detail_link": specDealLink_Detail }, "POST", "redirectRewardDealResult", "redirectRewardDealResult");
        //utils.call("http://localhost:50606/nhommua/deal_detail_new.aspx", { "flag": "redirectRewardDeal", "detail_link": specDealLink_Detail }, "POST", "redirectRewardDealResult", "redirectRewardDealResult");
    }
}
function redirectRewardDealResult(str) {
    if (str == "1") {
        var strUrlLocation = window.location.href;
        strUrlLocation = strUrlLocation.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        var strUrlLink = strPathLink_All.replace('tp-ho-chi-minh/', '').replace('ha-noi/', '');
        if (strUrlLocation.toLowerCase().indexOf("/yahoo/") != -1) {
            strUrlLink = strPathLink_All + "yahoo/";
        }
        window.location.href = strUrlLink + strStateNM + "/login.aspx";
        //window.location.href = "http://localhost:50606/NhomMuaV4/login.aspx";
    }
}